package com.cy.zs.hp.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cy.zs.hp.common.jsonResult.JsonResult;
import com.cy.zs.hp.model.SchedulingTable;
import com.cy.zs.hp.service.ISchedulingTableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 该表为医师排班表及候诊人数状态表 前端控制器
 * </p>
 *
 * @author cgb2008
 * @since 2020-11-28
 */
@Slf4j
@RestController
@RequestMapping("/hp/schedulingTable")
public class SchedulingTableController {
    @Autowired
    private ISchedulingTableService isched;

    /**
     *根据医生Id查询
     * @param id
     * @return
     */
    @RequestMapping("doFindByDoctorId/{id}")
    public JsonResult doFindByDoctorId(@PathVariable Integer id){
        List<SchedulingTable> times = isched.findByDoctorId(id);

        Date date=new Date();//此时date为当前的时间
        SimpleDateFormat dateFormat=new SimpleDateFormat("YYYY年MM月dd日");//设置当前时间的格式，为年月日
        for (SchedulingTable time:times) {
            Integer timeId = time.getId();
            String workTime = time.getWorkTime();//排班表时间
            String format = dateFormat.format(date);
            int i = workTime.compareTo(format);
            if(i<1){//删除排班表时间
                isched.deleteById(timeId);
            }

        }
        return new JsonResult(times);
    }

    @RequestMapping("/{doctorId}/{appointmentTime}")
    public JsonResult setdoctor(@PathVariable Integer doctorId,@PathVariable String appointmentTime) {
        System.out.println("工作表修改成功"+doctorId+appointmentTime);
        isched.setdoctor(doctorId,appointmentTime);

        return new JsonResult("工作表修改预约信息成功！");
    }

    @GetMapping("/{doctorId}")
    public JsonResult findSchedulingTableByDoctorId(@PathVariable Integer doctorId){
        List<SchedulingTable> workTimeTable = isched.findByDoctorId(doctorId);
        return new JsonResult(workTimeTable);
    }


}
